package com.duan.laugh.starter.email;

import java.util.*;

import static java.util.Collections.synchronizedMap;

/**
 * 内存中的邮箱账户
 *
 * @author duanjw
 */
public class InMemoryEmailAccountRepository implements EmailAccountRepository {
    private final Map<String,EmailAccount> emailAccounts = synchronizedMap(
            new LinkedHashMap());

    /**
     * 内存中的所有邮箱账户
     * @return
     */
    @Override
    public List<EmailAccount> getEmailAccounts() {
        return (List)emailAccounts.values();
    }

    /**
     * 根据邮箱账户id获取邮箱账户
     * @param id
     * @return
     */
    @Override
    public EmailAccount getEmailAccount(String id) {
        return emailAccounts.get(id);
    }

    /**
     * 新增邮箱账户
     * @param emailAccount
     */
    @Override
    public void add(EmailAccount emailAccount) {
        emailAccounts.put(emailAccount.getId(), emailAccount);
    }

    /**
     * 根据id删除邮箱账户
     * @param id
     */
    @Override
    public void delete(String id) {
        emailAccounts.remove(id);
    }
}
